package com.coding365.service.user.controller;


import com.coding365.service.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/register/{email}/{password}/{code}")
    public Boolean register(@PathVariable String email,
                            @PathVariable String password,
                            @PathVariable String code, HttpServletResponse response){
        return userService.register(email,password,code,response);

    }


    @GetMapping("/isRegistered/{email}")
    public Boolean isRegistered(@PathVariable String email){
        return userService.isRegistered(email);
    }


    @GetMapping("/login/{email}/{password}")
    public Boolean login(@PathVariable String email,
                        @PathVariable String password,
                        HttpServletResponse response){
        return userService.login(email,password,response);
    }

    @GetMapping("/info/{token}")
    public String getUserInfo(@PathVariable String token){
        return userService.getUserInfo(token);
    }


}
